<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<style>
    .message {
        color: red;
    }
</style>
<script type="text/javascript">
    var files_no = "";
    $(function () {
        var typeList = ${dictionariesTaskList};
        initSelect(false, "#typeList", typeList, false,"${task.type}");
        initCheckbox(false,"#managerList","charges",${managers},"${task.organizationtor}");

        $.CurrentDialog.find("#fileUpload").upload({
            uploader: "filesupload/uploadify/Task.shtml",
            fileSizeLimit: 1024,
            buttonText: "点击上传附件",
            fileTypeExts: "*.doc;*.docx;*.xls;*.xlsx;*.png;*.jpeg;*.jpg",
            icon: "cloud-upload",
            onUploadSuccess: "fileUploadSuccess",
            multi: "true",
            previewImg: false,
            dragDrop:true
        });
    });
    /**
     * 文件上传回调
     */
    function fileUploadSuccess(file, data, $element) {
        var json = $.parseJSON(data);
        if (json.code != 0) {
            $(document).alertmsg('error', '' + json.msg);
            return;
        }
        var file = json.data;
        var filename = file.name;
        var fileno = file.no;
        if (files_no == null || files_no == '') {
            files_no = $.CurrentDialog.find("#fileNo").val();
        }
        files_no += "," + fileno;
        var addli = '<li style="margin: 4px;" id="' + fileno + '"><a class="btn btn-gray">' + filename + '</a>&nbsp;&nbsp;&nbsp;&nbsp;' +
            '<a	class="btn btn-red"  data-mask="true" data-toggle="doajax" data-confirm-msg="请确认是否删除当前文件？" data-callback="delfileBack"  href="filesupload/deletefile/' + fileno + '.shtml?fileType=&pojoId=">删除</a>' +
            '</li>';
        $.CurrentDialog.find("#fileNo").val(files_no);
        $.CurrentDialog.find("#filename").append(addli);
    }

    /**
     * 文件删除
     */
    function delfileBack(json) {
        if (json.code == 0) {
            $(document).alertmsg('ok', '' + json.msg);
            $.CurrentDialog.find("#" + json.data).remove();
            if (files_no == null || files_no == '') {
                files_no = $.CurrentDialog.find("#fileNo").val();
            }
            files_no = files_no.replace(',' + json.data, '');
            $.CurrentDialog.find("#fileNo").val(files_no);
        } else {
            $(document).alertmsg('error', '' + json.msg);
        }
    }
</script>

<form action="task/submit/update.shtml" class="pageForm" id="addForm"
      data-toggle="validate" data-callback="doAjaxCallBackForDialog"
      method="post" data-toggle="ajaxform"
      data-validator-option="{stopOnError:false, timely:2}">
    <div class="bjui-pageContent">
        <div class="panel panel-default">
            <div class="panel-heading" align="center">编辑任务</div>
            <div class="panel-body">
                <input type="hidden" name="id" value="${task.id}">
                <input type="hidden" name="creator" value="${task.creator}">
                <input type="hidden" name="creatTime" value="${task.creatTime}">
                <input type="hidden" name="state" value="${task.state}">
                <table class="table table-condensed table-hover">
                    <tbody>
                    <tr>
                        <td><label class="control-label x180">主题：</label></td>
                        <td>
                            <input type="text" name="name" class="textChange" data-rule="required;length[~100]" value="${task.name}">
                            <span class="message" id="noMsg">*</span>
                        </td>
                        <td><label class="control-label x180">任务类型：</label></td>
                        <td>
                            <select name="type" id="typeList"
                                    data-width="210" class="form-control"
                                    data-toggle="selectpicker" data-size="10" data-live-search="true"
                                    data-rule="required;">
                            </select><span class="message">*</span>
                        </td>
                    </tr>
                    <tr>
                        <td><label class="control-label x180">任务时间：</label></td>
                        <td>
                            <input type="text" name="executeTime" class="textChange" data-rule="required;"
                                   data-toggle="datepicker" data-pattern="yyyy-MM-dd hh:mm:ss"
                                   data-min-date="%y-{%M-7}-%d" style="width: 210px" value="${task.executeTime}">
                            <span class="message">*</span>
                        </td>
                        <td><label class="control-label x180">任务地点：</label></td>
                        <td>
                            <input type="text" name="place" class="textChange" data-rule="required;length[~100]" value="${task.place}">
                            <span class="message">*</span>
                        </td>
                    </tr>
                    <tr>
                        <td><label class="control-label x180">主办联系人：</label></td>
                        <td>
                            <input type="text" name="contactstor" class="textChange" value="${task.contactstor}">
                        </td>
                        <td><label class="control-label x180">联系电话：</label></td>
                        <td>
                            <input type="text" name="phone" class="textChange" data-rule="mobile;" value="${task.phone}">
                        </td>
                    </tr>
                    <tr>
                        <td><label class="control-label x180">任务负责人：</label></td>
                        <td colspan="3" style="height: 50px;">
                            <div id="managerList" style="width: 650px;height:50px;padding: 3px;display:table-cell; vertical-align:middle;">

                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td><label class="control-label x180">备注：</label></td>
                        <td colspan="3">
                            <textarea cols="60" name="remark">${task.remark}</textarea>
                        </td>
                    </tr>
                    <tr>
                        <td><label class="control-label x180">附件：</label></td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <ul id="filename" style="font-size: 16px;display:inline;">
                                <c:forEach var="file" items="${sysFiles}" varStatus="index">
                                    <li style='margin: 4px;' id='${file.no}'>
                                        <c:choose>
                                            <c:when test="${fn:endsWith(file.name,'.jpg') || fn:endsWith(file.name,'.jpeg') || fn:endsWith(file.name,'.png')}">
                                                <a class="btn btn-blue" data-icon="image" data-resizable="false"
                                                   data-maxable="false" data-id="showPic" data-toggle="dialog"
                                                   data-height="660" data-width="880"
                                                   href="filesupload/showpic/${file.no}.shtml">${file.name}</a>
                                            </c:when>
                                            <c:otherwise>
                                                <a class="btn btn-blue"
                                                   href="filesupload/download/${file.no}.shtml">${file.name}</a>
                                            </c:otherwise>
                                        </c:choose>
                                        &nbsp;&nbsp;&nbsp;&nbsp;
                                        <a class="btn btn-red"  data-mask="true" data-toggle="doajax" data-confirm-msg="请确认是否删除当前文件？" data-callback="delfileBack"  href="filesupload/deletefile/${file.no}.shtml?fileType=Task&pojoId=${task.id}">删除</a>
                                    </li>
                                </c:forEach>
                            </ul>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td colspan="3">
                            <div style="float: right">
                                <input type="hidden" id="fileNo" name="files" value="${task.files}"/>
                                <div id="fileUpload" data-toggle="upload" style="display: inline;"></div>
                                <span style="color: #BFBFBF;">文件类型可为docx、xlsx、png、jpeg、jpg,大小不超过1M,文件名不超过40个字。</span>
                            </div>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="bjui-pageFooter">
        <ul>
            <li>
                <button type="submit" class="btn-primary">提交</button>
            </li>
            <li>
                <button type="button" class="btn-close">关闭</button>
            </li>
        </ul>
    </div>
</form>
